﻿using Hx.ADSyncPlatform.ActiveDirectory.Attributes;
using Hx.ADSyncPlatform.ActiveDirectory.Enums;
using Newtonsoft.Json.Converters;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;

namespace Hx.ADSyncPlatform.ActiveDirectory.Model
{
    /// <summary>
    /// 安全组
    /// </summary>
    public class Group : DirectoryObject
    {
        /// <summary>
        /// 组类型
        /// </summary>
        private GroupType groupType;
        [IgnoreUpdate]
        [RequiredForCreate]
        [JsonConverter(typeof(StringEnumConverter))]
        public GroupType GroupType
        {
            get
            {
                return groupType;
            }
            set
            {
                groupType = value;
                AssignedAttributes.Add(nameof(GroupType));
            }
        }

        /// <summary>
        /// 管理者
        /// </summary>
        private string managedBy;
        public string ManagedBy
        {
            get
            {
                return managedBy;
            }
            set
            {
                managedBy = value;
                AssignedAttributes.Add(nameof(ManagedBy));
            }
        }

        /// <summary>
        /// 成员
        /// </summary>
        private List<string> member;
        public List<string> Member
        {
            get
            {
                return member;
            }
            set
            {
                member = value;
                AssignedAttributes.Add(nameof(Member));
            }
        }

        /// <summary>
        /// 名称
        /// </summary>
        private string samAccountName;
        [IgnoreUpdate]
        [RequiredForCreate]
        public string SamAccountName
        {
            get
            {
                return samAccountName;
            }
            set
            {
                samAccountName = value;
                AssignedAttributes.Add(nameof(SamAccountName));
            }
        }

        /// <summary>
        /// 是否不显示在地址簿上
        /// </summary>
        private bool msExchHideFromAddressLists;
        public bool MsExchHideFromAddressLists
        {
            get
            {
                return msExchHideFromAddressLists;
            }
            set
            {
                msExchHideFromAddressLists = value;
                AssignedAttributes.Add(nameof(MsExchHideFromAddressLists));
            }
        }


        public string ParentOU
        {
            get
            {
                if (!string.IsNullOrEmpty(this.DistinguishedName) && this.DistinguishedName.Contains(","))
                {
                    string[] distinguishedNameArray = this.DistinguishedName.Split(",");
                    return string.Join(",", distinguishedNameArray.Skip(1));

                }
                return "";
            }
        }
    }
}
